<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/128x128.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/32x32.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/16x16.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="Powershell执行cmd的语法： 1cmd /c &quot;***Cmd语法&quot;    cmd遍历出列表： 12345dir /s /b c:\dir /s /b d:\dir /s /b c:\有权限的目录dir /s /b C:\Program Files只能遍历出当前有权限的目录列表   做成列表交给for循环： 1234for /f %i in (&apos;dir /s /b c:\1.txt&apos;)fo">
<meta property="og:type" content="article">
<meta property="og:title" content="cmd、bash、powershell所见即所学">
<meta property="og:url" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/index.html">
<meta property="og:site_name" content="laker&#39;s Blog">
<meta property="og:description" content="Powershell执行cmd的语法： 1cmd /c &quot;***Cmd语法&quot;    cmd遍历出列表： 12345dir /s /b c:\dir /s /b d:\dir /s /b c:\有权限的目录dir /s /b C:\Program Files只能遍历出当前有权限的目录列表   做成列表交给for循环： 1234for /f %i in (&apos;dir /s /b c:\1.txt&apos;)fo">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594976644450.png">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594976785660.png">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594977224435.png">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594977241244.png">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594977394913.png">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594977582414.png">
<meta property="og:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594977699028.png">
<meta property="og:updated_time" content="2020-07-27T08:45:06.920Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="cmd、bash、powershell所见即所学">
<meta name="twitter:description" content="Powershell执行cmd的语法： 1cmd /c &quot;***Cmd语法&quot;    cmd遍历出列表： 12345dir /s /b c:\dir /s /b d:\dir /s /b c:\有权限的目录dir /s /b C:\Program Files只能遍历出当前有权限的目录列表   做成列表交给for循环： 1234for /f %i in (&apos;dir /s /b c:\1.txt&apos;)fo">
<meta name="twitter:image" content="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/1594976644450.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/">





  <title>cmd、bash、powershell所见即所学 | laker's Blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">laker's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录渗透测试琐事仅仅</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            About
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="laker">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="laker's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">cmd、bash、powershell所见即所学</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2020-07-17T17:00:53+08:00">
                2020-07-17
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>Powershell执行cmd的语法：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cmd /c <span class="string">"***Cmd语法"</span></span><br></pre></td></tr></table></figure>

<hr>
<hr>
<p>cmd遍历出列表：</p>
<figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">dir</span> /s /b c:\</span><br><span class="line"><span class="built_in">dir</span> /s /b d:\</span><br><span class="line"><span class="built_in">dir</span> /s /b c:\有权限的目录</span><br><span class="line"><span class="built_in">dir</span> /s /b C:\Program Files</span><br><span class="line">只能遍历出当前有权限的目录列表</span><br></pre></td></tr></table></figure>

<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594976644450.png" alt="1594976644450"></p>
<p>做成列表交给for循环：</p>
<figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> /f %i <span class="keyword">in</span> ('<span class="built_in">dir</span> /s /b c:\<span class="number">1</span>.txt')</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /f %i <span class="keyword">in</span> ('<span class="built_in">dir</span> /s /b c:\<span class="number">111</span>.txt') <span class="keyword">do</span> <span class="built_in">echo</span> %i</span><br><span class="line">这条命令会搜集c盘下任意目录的<span class="number">111</span>.txt并且将其名字依次交给<span class="keyword">for</span>输出出来。<span class="keyword">for</span> /f 变量 <span class="keyword">in</span> (列表) <span class="keyword">do</span> 执行命令</span><br></pre></td></tr></table></figure>

<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594976785660.png" alt="1594976785660"></p>
<p>do可以使用&amp;拼接</p>
<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594977224435.png" alt="1594977224435"></p>
<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594977241244.png" alt="1594977241244"></p>
<hr>
<hr>
<p>Bash</p>
<p>遍历出一个列表:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">find / -name 1.txt</span><br><span class="line">查找所有命名（支持通配符*）</span><br></pre></td></tr></table></figure>

<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594977394913.png" alt="1594977394913"></p>
<p>遍历利用(管道符传入)：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">find / -name 1.txt|<span class="keyword">while</span> <span class="built_in">read</span> f;<span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">$f</span>; <span class="keyword">done</span></span><br><span class="line">语法：列表传入| <span class="keyword">while</span> <span class="built_in">read</span> 变量符号;<span class="keyword">do</span> 命令; <span class="keyword">done</span></span><br><span class="line">在<span class="keyword">do</span>处可用;连接多条命令</span><br></pre></td></tr></table></figure>

<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594977582414.png" alt="1594977582414"></p>
<p><img src="/2020/07/17/cmd、bash、powershell所见即所学/1594977699028.png" alt="1594977699028"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">find / -name bas.js|<span class="keyword">while</span> <span class="built_in">read</span> f;<span class="keyword">do</span> sh -c <span class="string">'id;pwd;ifconfig'</span> &gt; <span class="variable">$f</span>.txt;<span class="keyword">done</span></span><br></pre></td></tr></table></figure>


      
    </div>
    
    
    

    <div>
    
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

  <!-- JS库 sweetalert 可修改路径 -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <script src="https://cdn.bootcss.com/sweetalert/2.1.2/sweetalert.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/sweetalert/1.1.2/sweetalert.min.css">

  <p><span>本文标题:</span>cmd、bash、powershell所见即所学</p>
  <p><span>文章作者:</span>laker</p>
  <p><span>发布时间:</span>2020年07月17日 - 17:00:53</p>
  <p><span>最后更新:</span>2020年07月27日 - 16:45:06</p>
  <p><span>原始链接:</span><a href="/2020/07/17/cmd、bash、powershell所见即所学/" title="cmd、bash、powershell所见即所学">http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/</a>
    <span class="copy-path" title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="http://laker.xyz/2020/07/17/cmd、bash、powershell所见即所学/" aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>
</div>
<script>
    var clipboard = new Clipboard('.fa-clipboard');
    clipboard.on('success', $(function(){
      $(".fa-clipboard").click(function(){
        swal({
          title: "",
          text: '复制成功',
          html: false,
          timer: 500,
          showConfirmButton: false
        });
      });
    }));
</script>

    
    </div>

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/07/16/利用XServer解密APP/" rel="next" title="利用XServer解密APP">
                <i class="fa fa-chevron-left"></i> 利用XServer解密APP
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/07/27/前端-WAF-Bypass/" rel="prev" title="JS--WAF--Bypass">
                JS--WAF--Bypass <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">laker</p>
              <p class="site-description motion-element" itemprop="description">有幸，欢迎</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">tags</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.th3wind.xyz" title="th3wind" target="_blank">th3wind</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://damit5.com/" title="damit5" target="_blank">damit5</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">laker</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



    <br>
    <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
    <span class="post-meta-divider">|</span>
    <span id="busuanzi_container_site_uv">本站访客数<span id="busuanzi_value_site_uv"></span>人</span>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
